
//
//  VideoVC.m
//  Lucode
//
//  Created by lanou3g on 15/10/13.
//  Copyright © 2015年 liudi. All rights reserved.
//

#import "VideoVC.h"
#import "VideoTableViewCell.h"
#import "NextVideoViewController.h"
#import "VideoModle.h"
#import "AfnHelper.h"
#import "AFNetworking.h"

@interface VideoVC ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) NSMutableArray *mutArray;

@end


static NSString *identifier = @"identifier";

@implementation VideoVC

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor yellowColor];

#pragma mark ------------ tableView初始化 --------------
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [_tableView registerClass:[VideoTableViewCell class] forCellReuseIdentifier:identifier];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [self.view addSubview:_tableView];

#pragma mark ------------ 请求数据 -------------
    __weak typeof(self) temp = self;
    [AfnHelper getDataWithUrl:@"http://box.dwstatic.com/apiNewsList.php?action=l&newsTag=upgradenews&p=1" dic:nil sucess:^(id opreation) {
        NSDictionary *dic = opreation;
        NSArray *arr = dic[@"data"];
        for (NSDictionary * dict in arr) {
            VideoModle *modle = [[VideoModle alloc] init];
            [modle setValuesForKeysWithDictionary:dict];
            [temp.mutArray addObject:modle];
        }
        [self.tableView reloadData];
    } faile:^(id error) {
    }];
}

#pragma mark ------------- tableView ------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.mutArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    VideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    VideoModle *modle = self.mutArray[indexPath.row];
    cell.video = modle;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 110;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NextVideoViewController *nextVC = [[NextVideoViewController alloc] init];

    VideoModle *modle = self.mutArray[indexPath.row];
    nextVC.string = modle.commentUrl;

    [self.navigationController pushViewController:nextVC animated:YES];
}

- (NSMutableArray *)mutArray{
    if (!_mutArray) {
        _mutArray = [NSMutableArray array];
    }
    return _mutArray;
}



@end
